<template>
    <div class="tpl-content-wrapper">
    <ol class="am-breadcrumb">
      <li><a href="#" class="am-icon-home">首页</a></li>
      <li><a href="#">平台用户</a></li>
      <li class="am-active">操作日志</li>
    </ol>
      <div class="tpl-portlet-components">
    <div class="tpl-block">
      <div class="am-g">
        <div class="am-u-sm-12">
          <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
                <tr>
                  <th class="table-id">序号</th>
                  <th>eid</th>
                  <th class="am-hide-sm-only">操作模块</th>
                  <th>类型</th>
                  <th class="am-hide-sm-only">请求地址</th>
                  <th class="am-hide-sm-only">模块名称</th>
                  <th>操作用户</th>
                  <th class="am-hide-sm-only">用户账号</th>
                  <th class="am-hide-sm-only">操作时间</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(list, index) in lists">
                  <td>{{index + 1}}</td>
                  <td>{{list.eid}}</td>
                  <td class="am-hide-sm-only">{{list.name}}</td>
                  <td>{{changeType(list.type)}}</td>
                  <td class="am-hide-sm-only">{{list.module}}</td>
                  <td class="am-hide-sm-only">{{list.moduleName}}</td>
                  <td>{{list.mUserName}}</td>
                  <td class="am-hide-sm-only">{{list.mUserAcount}}</td>
                  <td class="am-hide-sm-only">{{list.ctime | date}}</td>
                </tr>
              </tbody>
            </table>
          </form>
          <pager :allCount="allCount" :count="count" :page="page" @changePage="changePage" @renovate="renovate"></pager>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
 import * as apis from '../../../apis'
 import excel from '../../../assets/excel'
  export default {
    data() {
      return {
        lists: [],
        fuzzy: '', sctime: '', ectime: '',
        count: 0,
        page: 1,
        pageSize: 20,
        ex: {name: '', page: 1, pageSum: 0}
      }
    },
    created() {
      this.getCount()
    },
    methods: {
      changeType (type) {
        switch (type) {
          case 'insert':
            type = '插入数据'
            break
          case 'update':
            type = '修改数据'
            break
          case 'start-audit':
            type = '开始审核'
            break
          case 'audit':
            type = '审核通过'
            break
          case 'no-audit':
            type = '审核不通过'
            break
          case 'delete':
            type = '删除'
            break
          case 'stop':
            type = '暂停项目'
            break
          case 'restore':
            type = '重启项目'
            break
          case 'end':
            type = '结束项目'
            break
        }
        return type
      },
      getCount() {
        apis.ptoperlogCount(this.fuzzy, this.sctime, this.ectime).then(({data: data}) => {
          console.log('data', data)
          this.allCount = data.result.operlogCount
          this.count = Math.ceil(data.result.operlogCount / this.pageSize)
          this.ex.pageSum = Math.ceil(data.result.operlogCount / 500)
          if (data && data.result_code === 1 && data.result.operlogCount > 0) {
            this.getLists()
          } else {
            this.lists = []
          }
        })
      },
      getLists() {
        apis.ptoperlogList(this.page, this.pageSize, this.fuzzy, this.sctime, this.ectime).then(({data: data}) => {
          if (data && data.result_code === 1 && data.result.operlogList) {
            this.lists = data.result.operlogList
          }
        })
      },
      changePage(page) {
        this.page = page
        this.getLists()
      },
      onSearch() {
        this.page = 1
        this.getCount()
      },
       setSctime(val) {
        this.sctime = val
      },
      setEctime(val) {
        this.ectime = val
      },
      renovate (page) {
        this.getCount()
      },
      excelExport (name, page) {
        let col = {name: '操作模块', ctime: {name: '操作时间', time: 1}, type: '类型', module: '请求地址', moduleName: '模块名称', mUserName: '操作用户', mUserAcount: '用户账号'}
        apis.operlogList(page, 500).then(({data: data}) => {
          if (data && data.result_code === 1 && data.result.operlogList) {
            let rows = data.result.operlogList
            excel.export(col, rows, name)
            this.ex.name = ''
            this.ex.page = 1
          }
        })
      }
    }
  }
</script>